package com.yang.server;

import com.yang.mapper.TaskReplacementMapper;
import com.yang.pojo.TaskReplacement;
import com.yang.util.ApplicationContextProvider;
import org.apache.poi.ss.formula.functions.Trend;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author 杨天可
 * @Date 2021/3/30 14:26
 * @Version 1.0
 */

@Scope("prototype")
@Service("taskReplacementServer")
public class TaskReplacementServer extends Thread {

    private static final Logger log = LoggerFactory.getLogger(TaskReplacementServer.class);

    @Resource
    TaskReplacementMapper taskReplacementMapper;

    @Override
    public void run() {
        try {
            List<TaskReplacement> notApproval = taskReplacementMapper.findNotApproval(1);
            while (notApproval.size() > 0) {
                for (TaskReplacement taskReplacement : notApproval) {
                    log.info("请假审核向主任务表中添加，监听中--------------");
                    TaskReplacementServerStart taskReplacementServerStart = ApplicationContextProvider.
                            getBean("taskReplacementServerStart", TaskReplacementServerStart.class);
                    taskReplacementServerStart.setTaskReplacement(taskReplacement);
                    taskReplacementServerStart.start();
                }
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}
